var app = getApp();
Page({
  data: {
    imgUrls: [
      app.myUlife.ulifeUrl + '/wx/topimg2.jpg',
    ],
    imgdefalut: app.myUlife.ulifeUrl + '/wx/topimg2.jpg',
    icon: '../../assets/images/iconfont-help.png',
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 1200,
    whklen:false,
    sthdlen: false,
    whks:[],
    sthds:[]
  }, 
  onLoad: function () {
    //加载首页分类
    this.getCatagory();
    //加载顶部图片
    this.getsystemset();
  },
  showtishi: function (e) {
    wx.showModal({
      title: '友情提示',
      content: '该服务暂未开放!',
      showCancel: !1,
    })
  },
   //加载首页分类
  getCatagory: function (e) {
    var csid = wx.getStorageSync('csid');
    var nj = wx.getStorageSync('nj');
    var bj = wx.getStorageSync('bj');

    var that = this;
    wx.request({
      url: app.myUlife.ulifeUrl + 'wechart/getCategory.html', 
      data:{
        csid: csid,
        nj: nj,
        bj: bj
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var whks = res.data.whks;
        var sthds = res.data.sthds;
        if (whks.length>0){
          that.setData({
            whklen: true
          });
        } 
        if (sthds.length > 0) {
          that.setData({
            sthdlen: true
          });
        }
        that.setData({
          whks: whks,
          sthds: sthds
        });
      }
    })
  },

  //加载顶部图片
  getsystemset: function (e) {
    var csid = wx.getStorageSync('csid');
    var that = this;
    wx.request({
      url: app.myUlife.ulifeUrl + 'getsystemSet.html',
      data: {
        csid: csid,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var imgUrls=[];
        var topimage1s = res.data.TOPIMAGE1S;
        if (topimage1s!=null && topimage1s!=undefined && topimage1s=="0"){
          var topimage1 = res.data.TOPIMAGE1;
          if (topimage1 != null && topimage1 != undefined){
            imgUrls.push(app.myUlife.ulifeUrl+topimage1);
          }
        }

        var topimage2s = res.data.TOPIMAGE2S;
        if (topimage2s != null && topimage2s != undefined && topimage2s == "0") {
          var topimage2 = res.data.TOPIMAGE2;
          if (topimage2 != null && topimage2 != undefined) {
            imgUrls.push(app.myUlife.ulifeUrl+topimage2);
          }
        }

        var topimage3s = res.data.TOPIMAGE3S;
        if (topimage3s != null && topimage3s != undefined && topimage3s == "0") {
          var topimage3 = res.data.TOPIMAGE3;
          if (topimage3 != null && topimage3 != undefined) {
            imgUrls.push(app.myUlife.ulifeUrl+topimage3);
          }
        }

        that.setData({
          imgUrls: imgUrls
        })
        
      }
    })
  },



  errorFunction: function (e) {
    console.log(e);
    if (e.type == "error") {
      var errorImgIndex = e.target.dataset.errorimg 
      var imgUrls = this.data.imgUrls    　　　　　　　//将图片列表数据绑定到变量
      imgUrls[errorImgIndex] = this.data.imgdefalut //错误图片替换为默认图片
      this.setData({
        imgUrls: imgUrls
      })
    }
  }

})